package cn.tedu.em.car.webapi.controller;

import cn.tedu.em.car.service.ICarService;
import cn.tedu.em.common.pojo.car.dto.CarAddNewDTO;
import cn.tedu.em.common.pojo.car.dto.CarUpdateDTO;
import cn.tedu.em.common.pojo.car.vo.CarListVO;
import cn.tedu.em.common.restful.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cars")
@Api(tags = "车辆管理模块")
@Slf4j
public class CarController {

    @Autowired
    private ICarService carService;

    @PostMapping("/add-new")
    @ApiOperation("新增车辆")
    public JsonResult<Void> addNew(CarAddNewDTO carAddNewDTO){
        log.debug("开始处理新增车辆的请求");
        carService.addNew(carAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/delete")
    @ApiOperation("根据id删除车辆")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("开始处理根据id删除车辆的请求");
        carService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改车辆信息")
    public JsonResult<Void> updateCarInfo(CarUpdateDTO carUpdateDTO){
        log.debug("开始处理修改车辆信息的请求");
        carService.updateCarInfo(carUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/list")
    @ApiOperation("查询车辆列表")
    public JsonResult<List<CarListVO>> list(){
        log.debug("开始处理查询车辆列表的请求");
        List<CarListVO> list = carService.getCarList();
        return JsonResult.ok(list);
    }



}
